package cn.ekuma.epos.datalogic.define.dao.sale;

import java.util.List;

import cn.ekuma.data.dao.ViewDAO;
import cn.ekuma.util.JsonUtil;

import com.openbravo.bean.sales.TicketLine_V;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.QBFBuilder;
import com.openbravo.data.loader.SerializerWriteBasic;
import com.openbravo.data.loader.StaticSentence;

public class TicketLine_VDAO extends ViewDAO<TicketLine_V>{

	public TicketLine_VDAO(I_Session s) {
		super(s);
		
	}

	@Override
	public Class getSuportClass() {
		return TicketLine_V.class;
	}

	@Override
	public TicketLine_V readValues(DataRead dr, TicketLine_V obj)
			throws BasicException {
		if(obj==null)
        	obj=new TicketLine_V();
        obj.setM_iTicketId(dr.getInt(1));
        obj.setTicketType(dr.getInt(2));
        obj.setM_dDate(dr.getTimestamp(3));
        obj.setLocation(dr.getString(4));
        obj.setUserName(dr.getString(5));
        obj.setCustomerName(dr.getString(6)); 
        obj.setDefaultPrice(dr.getDouble(7));
        obj.setAttsetinstid(dr.getString(8));
        obj.setMultiply(dr.getDouble(9));
        obj.setPrice(dr.getDouble(10));
        obj.setAttributes(JsonUtil.getHashMap(dr.getString(11)));
        obj.setPriceRate(dr.getDouble(12));
        obj.setPrefSell(dr.getBoolean(13));
        obj.setConsultCost(dr.getDouble(14));
        obj.setLotNo(dr.getString(15));
        obj.setScore(dr.getDouble(16));
        obj.setSaleMan(dr.getString(17));
        return obj;
	}
	
	public List<TicketLine_V> listSaleManTicketLine(Object filter) throws BasicException {
		return new StaticSentence(s, new QBFBuilder(
                "SELECT T.TICKETID, T.TICKETTYPE, T.CURDATE, S.NAME, P.NAME, C.NAME, L.DEFAULTPRICE, ATS.VALUE, L.UNITS, L.PRICE,L.ATTRIBUTES,L.PRICERATE,L.ISPREFSELL,L.CONSULTCOST,L.LOTNO,L.SCORE,L.SALEMAN  "
                + "FROM TICKETLINES L LEFT  JOIN TICKETS T ON L.TICKET = T.ID LEFT OUTER JOIN CUSTOMERS C ON C.ID = T.CUSTOMER LEFT OUTER JOIN LOCATIONS S ON S.ID = T.LOCATIONREF LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID  "
                + "LEFT OUTER JOIN  ATTRIBUTEINSTANCE ATS ON L.ATTRIBUTESETINSTANCE_ID=ATS.ID "
                + "WHERE ?(QBF_FILTER) AND SALEMAN IS NOT NULL  ORDER BY T.CURDATE DESC ", new String[]{"T.CURDATE", "T.CURDATE", "L.SALEMAN", "T.LOCATIONREF"}), new SerializerWriteBasic(Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING),this).list(filter);

	}

}
